<template>

  <div>
    <el-row class="params">
      <label class="row-lable">订单编号:</label>
      <el-input style="width:160px" v-model="tradeCode"></el-input>
      <label class="row-lable">买家id:</label>
      <el-input style="width:160px" v-model="buyerId"></el-input>
      <label class="row-lable">推荐人id:</label>
      <el-input style="width:160px" v-model="agentId"></el-input>
      <el-button type="primary" @click="jump(1)">搜索</el-button>
      <label>状态</label>
      <el-select v-model="status" @change="jump(1)">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
    </el-row>

    <el-table :data="listData" border highlight-current-row stripe style="width: 100%;margin-top: 20px">
      <el-table-column prop="tradeCode" label="订单号"></el-table-column>
      <el-table-column prop="payTime" label="下单时间"></el-table-column>
      <el-table-column prop="sendTime" label="发货时间"></el-table-column>
      <el-table-column label="买家信息">
        <template slot-scope="scope">
          <template>id:{{scope.row.buyerId}}</template>
          <br>
          <template>{{scope.row.buyer}}</template>
        </template>
      </el-table-column>
      <el-table-column label="邀请人信息">
        <template slot-scope="scope">
          <template v-if="scope.row.agent">
            ID:{{scope.row.agent.agentId}}
            <br>
            昵称:{{scope.row.agent.nick}}
            <br>
            职务:{{scope.row.agent.dutyName}}
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="itemCode" label="商品编号"></el-table-column>
      <el-table-column label="下单商品信息">
        <template slot-scope="scope">
          <img :src="scope.row.imgUrl" style="max-height: 60px;max-width: 60px">
          <br>
          <template>{{scope.row.title}}</template>
        </template>
      </el-table-column>
      <el-table-column label="实付金额">
        <template slot-scope="scope">
          <template>{{scope.row.payMoney}}</template>
          <br>
          <template>(含运费：{{scope.row.postFee}})</template>
        </template>
      </el-table-column>
      <el-table-column label="规格">
        <template slot-scope="scope">
          <template>{{scope.row.sku}}；</template>
          <template>数量{{scope.row.num}}</template>
        </template>
      </el-table-column>
      <el-table-column label="收货信息">
        <template slot-scope="scope">
          <template>姓名:{{scope.row.receiveName}}</template>
          <br>
          <template>电话:{{scope.row.receiveTelephone}}</template>
          <br>
          <template>地址:{{scope.row.provName}}{{scope.row.cityName}}{{scope.row.areaName}}{{scope.row.receiveDetail}}
          </template>
        </template>
      </el-table-column>
      <el-table-column label="物流">
        <template slot-scope="scope">
          <template>物流单号：{{scope.row.postCode}}</template>
          <br>
          <template>物流公司：{{scope.row.postCompany}}</template>
        </template>
      </el-table-column>
      <el-table-column>
        <template slot-scope="scope">
          <!--订单状态 1已发货 2 已收货 3退货中 4退货完成-->
          <template v-if="scope.row.sendStatus===1">
            已发货
          <!--<el-button size="mini" type="primary" @click="openRefund(scope.row.tradeId)">退款</el-button>-->
          </template>
          <template v-if="scope.row.sendStatus===4">已退货</template>
        </template>
      </el-table-column>
      <el-table-column label="备注">
        <template slot-scope="scope">
          <template>{{scope.row.remark}}</template>
          <el-button type="text" @click="remarkModBtn(scope.row)">备注</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog type="text" :modal-append-to-body="false" :visible.sync="remarkShow" width="30%">
      <el-form>
        <el-form-item label="备注">
          <el-input v-model="remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
         <el-button @click="remarkShow = false">取 消</el-button>
         <el-button type="primary" @click="modRemarkOK">确 定</el-button>
       </span>
    </el-dialog>

    <el-pagination
      background
      @current-change="jump"
      layout="total, prev, pager, next, jumper"
      :pageSize=15
      :total="total">
    </el-pagination>

  </div>

</template>

<script>
  import {ajax, sendedList, remarkOrder} from "../../data/service";

  export default {
    name: "sendedList",
    data() {
      return {
        tradeCode: '',
        listData: [],
        page: 1,
        total: 0,
        remarkShow: false,
        remark: '',
        buyerId: '',
        status: 1,
        options: [
          {
            label: "全部",
            value: 1
          },
          {
            label: "已发货",
            value: 2
          },
          {
            label: "已退款",
            value: 3
          }
        ],
        agentId:''
      }
    },
    mixins: [ajax],
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.doajax(sendedList,
          {
            page: this.page,
            tradeCode: this.tradeCode===undefined?"":this.tradeCode,
            buyerId:this.buyerId===undefined?"":this.buyerId,
            status:this.status,
            agentId:this.agentId === undefined?"":this.agentId
          }, (resp) => {
            this.listData = resp.data;
            this.total = resp.total;
          })
      },

      remarkModBtn(row) {
        this.tradeCode = row.tradeCode;
        this.remark = row.remark;
        this.remarkShow = true;
      },

      modRemarkOK() {
        this.doajax(remarkOrder, {tradeCode: this.tradeCode, remark: this.remark}, (resp) => {
          this.remark = resp.remark;
          this.remarkShow = false;
          this.tradeCode = '';
          this.getList();
        })
      },

      exportBtn() {
        window.location.href = '/adminjson/exportTradeList.json';
      },

      jump(val) {
        this.page = val;
        this.getList();
      },
    }
  }
</script>

<style scoped>

</style>
